import 'dart:core';
import 'package:acgn_pioneer/models/_index.dart';

import '../public.dart';
import 'base_model.dart';

/// 评论
class CommentModel extends BaseModel {
  int id; //评论标识
  String content; //评论内容
  int fatherId; // 评论父id
  int createTime; // 发表时间
  String images; // 评论图片
  int ssid; // 评论主体id
  int ssidType = 0; // 评论类型 0：漫画 1：社区 2：游戏 3：书单 4：小说
  String title; // 评论主体名称
  String url; // 评论主体链接
  int relateId; // 评论关联id（章节）
  String deviceTail; // 设备名称
  int supportCount; // 点赞数量
  bool isSupport = false; // 已点赞标识
  int isElite = 0; // 加精标识 1.加精
  int isTop = 0; // 1.置顶
  int revertCount; // 回复数量
  int userIdentifier; // 发表评论用户id
  String uName; // 发表评论用户名字
  int replyUserId; // 回复用户id
  String floorDesc; // 楼层（沙发、板凳、地板、第n楼等）
  List<CommentModel> lstChildren = []; // 子评论列表

  CommentModel(
      {this.content,
      this.title,
      this.ssid,
      this.relateId,
      this.fatherId,
      this.userIdentifier});

  CommentModel.fromJson(Map<String, dynamic> data) : super.fromJson(data) {
    id = data['id'];
    content = data['content'];
    if (content.contains('reply')) {
      // 有些回复会有特殊回复内容如：{reply:“237563187”}放大放大放大说,去除掉
      content = content.replaceAll(RegExp(r'({reply:[^}]*})'), '');
    }
    fatherId = data['fatherid'];
    createTime = data['createtime'];
    images = data['images'];
    ssid = data['ssid'];
    ssidType = data['ssidtype'];
    title = data['title'];
    relateId = data['relateid'] != '' ? int.parse(data['relateid']) : 0;
    deviceTail = data['device_tail'];
    supportCount = data['supportcount'];
    isElite = data['iselite'];
    isTop = data['istop'];
    revertCount = data['revertcount'];
    userIdentifier = data['useridentifier'];
    uName = data['uname'];
    floorDesc = data['floor_desc'];
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'content': content,
      'fatherId': fatherId,
      'createTime': createTime,
      'images': images,
      'ssid': ssid,
      'ssidType': ssidType,
      'title': title,
      'url': url,
      'relateId': relateId,
      'deviceTail': deviceTail,
      'supportCount': supportCount,
      'isSupport': isSupport,
      'isElite': isElite,
      'isTop': isTop,
      'revertCount': revertCount,
      'userIdentifier': userIdentifier,
      'uName': uName,
      'replyUserId': replyUserId,
      'floorDesc': floorDesc
    };
  }
}
